package com.cskaoyan._03api;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/21 16:32
 **/

public class StopDemo {
    public static void main(String[] args) {
        System.out.println("main start");
        // 创建线程对象
        StopThread t = new StopThread();
        // start
        t.start();

        // main打印3个数
        for (int i = 0; i < 3; i++) {
            System.out.println(Thread.currentThread().getName() +
                    "----" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("main end");
        // 中断线程 stop() 过时的方法
        t.stop();
    }
}

class StopThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(getName()+"----"+i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 保存用户数据到数据库
        }
    }
}